package com.why.blog.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
  * 设置虚拟路径，访问绝对路径下资源
  */
@Slf4j
@Configuration
//@ConfigurationProperties(prefix = "file")
public class UploadConfig implements WebMvcConfigurer{
    //访问静态资源的请求    /uploadimg/**
    @Value("${file.staticAccessPath}")
    private String staticAccessPath;
    //静态资源的请求被映射到yaml文件中设置的位置
    @Value("${file.uploadFolder}")
    private String uploadFolder;
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        log.warn(staticAccessPath);
        log.warn(uploadFolder);
        registry.addResourceHandler(staticAccessPath).addResourceLocations("file:" + uploadFolder);
    }
}